package com.silverbox.sweeporder.common;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.spring.autoconfigure.MeterRegistryCustomizer;

/**
 * 配置MeterRegistry监控参数
 * @author caojx
 * @date 2018年11月30日
 */
@Configuration
public class MeterRegistryConfig {
	
	@Value("${spring.application.name}")
	private String application;
/*	
	@Value("${server.address}")
	private String instance;*/
	
	@Bean
    MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
        return registry -> {
            registry.config().commonTags("application", application);
            try {
				registry.config().commonTags("instance", InetAddress.getLocalHost().getHostAddress());
			} catch (UnknownHostException e) {
				e.printStackTrace();
			}
        };
    }
	
}